/**
	This file is part of MemoryTrace.

	MemoryTrace is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

        Written by Ameziane NAIT ABDELAZIZ.
        
	MemoryTrace is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with MemoryTrace.  If not, see <http://www.gnu.org/licenses/>.
**/

/**
 * !\file   stack_trace.h
 * \author Ameziane NAIT ABDELAZIZ
 * \brief Ensemble de routines permettant de faire du backtracing
 */

#ifndef STACK_TRACE_H
#define	STACK_TRACE_H

#define MAX_SYMBOLE_LENGTH 1024
#define STACK_TRACE_SIZE sizeof(symbole_t)
#define DELIMITEUR "#"
#define DELIMITEUR_2 "|"

#include <string>


/**
 * \brief structure encapsulant une backtrace
 */
typedef struct {
    
    /**
     * \brief
     */
    unsigned int length;    //4 octets
    /**
     * \brief
     */
    char symb     [MAX_SYMBOLE_LENGTH];//1024
}symbole_t;

/**
 * \brief structure regroupant le nom des fonctions qui font de l'allocation dynamique
 */
typedef struct {
    std::string* parent;
    std::string* p_parent;
}callers_tree;

/**
 * \brief demangle le symbole qu'on lui passe sous forme de chaine c
 */
std::string* demangle(char * sym);


/**
 * \brief
 * @param sym
 */
callers_tree* demangle_(symbole_t * sym);

/**
 * \brief
 */
void getCallerByLevel(symbole_t* content,int level);

/**
 * \brief
 */
void getCaller(symbole_t* content);

/**
 * \brief ecrit la fonction appelant cette methode dans fd 
 * @param content
 * @param fd
 */
void getCaller_fd(int fd);

/**
 * \brief ecrit dans le fichier fd la stack_trace
 */
void getCallerByLevel_fd(int level,int fd);
#endif	/* STACK_TRACE_H */

